import urllib.request
import urllib.parse
import chardet

user = 'User-Agent','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36'
while True:
    addr = input('请输入URL：')
    req=urllib.request.Request(addr)
    req.add_header(user)
    
    response = urllib.request.urlopen(req)
    html = response.read()

    dict1=chardet.detect(html)
    code = dict1['encoding']
    print('该网页使用的编码是：%s'% (code))
